set groups {{cfg_group}} policy-options policy-statement EVPN-LB term term1 from protocol evpn
set groups {{cfg_group}} policy-options policy-statement EVPN-LB term term1 then load-balance per-packet
set groups {{cfg_group}} routing-options forwarding-table export EVPN-LB
{%     for ri in device_abstract_config.get('routing_instances', []) %}
{%         if ((ri.get('routing_instance_type') == 'virtual-switch') and (ri.get('comment') != 'PNF-Service-Chaining')) or (ri.get('virtual_network_is_internal') == true) or ((ri.get('routing_instance_type') == 'vrf') and (ri.get('is_public_network') == true)) %}
{%             set vrf_import = ri.name+'-import' %}
{%             set vrf_export = ri.name+'-export' %}
{%             for import_target in ri.get('import_targets', []) %}
{%                 set community_target = import_target.replace(':', '_') %}
set groups {{cfg_group}} policy-options policy-statement {{vrf_import}} term t1 from community {{community_target}}
set groups {{cfg_group}} policy-options community {{community_target}} members {{import_target}}
{%             endfor %}
set groups {{cfg_group}} policy-options policy-statement {{vrf_import}} term t1 then accept
set groups {{cfg_group}} switch-options vrf-import {{vrf_import}}
{%             for export_target in ri.get('export_targets', []) %}
{%                 set community_target = export_target.replace(':', '_') %}
set groups {{cfg_group}} policy-options policy-statement {{vrf_export}} term t1 then community add {{community_target}}
set groups {{cfg_group}} policy-options community {{community_target}} members {{export_target}}
{%             endfor %}
set groups {{cfg_group}} policy-options policy-statement {{vrf_export}} term t1 then accept
{%         endif %}
{%     endfor %}
{%     for bgp_elem in device_abstract_config.get('bgp', []) %}
{%         set families = bgp_elem.get('families', []) %}
{%         for fam in families %}
{%             if fam == 'evpn' %}
{%                 set route_distinguisher = bgp_elem.get('ip_address') %}
{%                 set as_number = bgp_elem.get('autonomous_system') %}
set groups {{cfg_group}} protocols evpn encapsulation vxlan
set groups {{cfg_group}} protocols evpn extended-vni-list all
set groups {{cfg_group}} switch-options vtep-source-interface lo0.0
set groups {{cfg_group}} switch-options route-distinguisher {{route_distinguisher}}:1
set groups {{cfg_group}} switch-options vrf-target target:{{as_number}}:1
set groups {{cfg_group}} policy-options community community-esi-in members target:{{as_number}}:1
set groups {{cfg_group}} policy-options policy-statement import-evpn term esi-in from community community-esi-in
set groups {{cfg_group}} policy-options policy-statement import-evpn term esi-in then accept
set groups {{cfg_group}} policy-options policy-statement import-evpn term default-term then reject
set groups {{cfg_group}} switch-options vrf-import REJECT-MAINTENANCE-MODE
set groups {{cfg_group}} switch-options vrf-import import-evpn
{%                 for ri in device_abstract_config.get('routing_instances', []) %}
{%                     set name = ri.get('name') %}
{%                     set vxlan_id = ri.get('vxlan_id', '') %}
{%                     if (vxlan_id != '') and (ri.get('routing_instance_type', '') == 'virtual-switch') %}
{%                         for export_target in ri.get('export_targets', []) %}
set groups {{cfg_group}} protocols evpn vni-options vni {{vxlan_id}} vrf-target {{export_target}}
{%                         endfor %}
{%                     endif %}
{%                 endfor %}
{%             endif %}
{%         endfor %}
{%     endfor %}
